import { LogUtil } from '../../core';
import { IPSAppDELogic, IPSDELogicLinkSingleCond } from '../../exports';
import { IPSModelObject } from '../../ipsmodel-object';
import { PSModelServiceProxyImpl } from '../../psmodel-service-proxy-impl';

/**
 * 全局默认通用代理
 *
 * @author chitanda
 * @date 2021-06-08 20:06:55
 * @export
 * @class PSDELogicLinkSingleCondServiceProxy
 * @extends {PSModelServiceProxyImpl}
 */
export class PSDELogicLinkSingleCondServiceProxy extends PSModelServiceProxyImpl {
  getPSModel4(
    relatedPSModelObject: IPSModelObject,
    cls: string,
    objNode: any,
    strTag: string,
  ): IPSModelObject {
    switch (strTag) {
      case 'getDstLogicParam':
        return this.getDstLogicParam(
          relatedPSModelObject as IPSDELogicLinkSingleCond,
          objNode,
        );
    }
    return this.getRealPSModelService().getPSModel4(
      relatedPSModelObject,
      cls,
      objNode,
      strTag,
    );
  }

  getDstLogicParam(
    relatedPSModelObject: IPSDELogicLinkSingleCond,
    obj: any,
  ): any {
    if (obj.modelref) {
      const logic = this.getParentPSModelObject(
        relatedPSModelObject,
        'app.dataentity.IPSAppDELogic',
      ) as IPSAppDELogic;
      if (logic) {
        return logic.findPSDELogicParam(obj);
      } else {
        LogUtil.error(
          `查找主逻辑失败，无法从主逻辑中获取「getDstLogicParam」对应的逻辑参数。`,
          relatedPSModelObject,
          obj,
        );
      }
    }
    return null;
  }
}
